package com.googlecode.jvmpart.support;

import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.googlecode.jvmpart.Partitioner;
import com.googlecode.jvmpart.ProcessExecution;
import com.googlecode.jvmpart.ProcessExecutionSplitter;
import com.googlecode.jvmpart.proc.JvmProcessException;

/**
 * Sample split a set of jvm processed to execute
 * @author chunzhan.he
 *
 */
public class SampleJvmExecutionSpliter implements ProcessExecutionSplitter {
	public Set<ProcessExecution> split(Partitioner partitioner, int capacity) throws JvmProcessException {
		Map<String, Map<String, Object>> map = partitioner.partition(capacity);
		Set<ProcessExecution> set = new HashSet<ProcessExecution>(map.size());
		for(Entry<String, Map<String, Object>> entry:map.entrySet()) {
			ProcessExecution threadExecution = new ProcessExecution();
			threadExecution.setName(entry.getKey());
			Map <String, Object>params = entry.getValue();
			threadExecution.setParams(params);
			set.add(threadExecution);
		}
		return set;
	}

}
